package com.example.backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.backend.entity.Comment;
import com.example.backend.entity.CommentVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author Jcy
 * @Date 2022/5/5
 */
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {
    @Select("SELECT tb_comment.comment_id FROM tb_comment WHERE tb_comment.comment_post_id =#{postId}")
    List<Integer> getCommentId(@Param("postId") int postId);
    @Select("SELECT DISTINCT tb_comment.comment_id AS commentId,(SELECT tb_user.nickname from tb_user WHERE tb_user.user_id = (SELECT tb_comment.comment_user_id FROM tb_comment WHERE tb_comment.comment_id = commentId)) AS name,(SELECT tb_comment.comment_content FROM tb_comment WHERE tb_comment.comment_id = commentId) AS content FROM tb_post,tb_user,tb_comment")
    List<CommentVO> getComments(Page<CommentVO> page);
}
